<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>2班抽奖</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    h2 {
      text-align: center;
    }

    .box {
      width: 600px;
      margin: 50px auto;
      display: flex;
      font-size: 25px;
      line-height: 40px;
    }

    .qs {

      width: 450px;
      height: 40px;
      color: red;

    }

    .btns {
      text-align: center;
    }

    .btns button {
      width: 120px;
      height: 35px;
      margin: 0 50px;
    }
  </style>
</head>

<body>
  <h2>随机点名</h2>
  <div class="box">
    <span>大冤种：</span>
    <div class="qs">请点击开始进行抽奖</div>
  </div>
  <div class="btns">
    <button class="start">开始</button>
    <button class="end">结束</button>
  </div>

  <script>
    // 数据数组
    const arr = ["刘宏伟", "朱俊玮", "郭世芳", "吴慧玉", "许嘉成", "陈乐斌", "李语希", "李文明", "杜晓龙", "邹家华", "朱伊依", "周磊", "赖特凯伦", "轸亚琪", "李佳豪", "尤志昆", "陈兴富", "廖靖宇", "钟俊宇", "徐文皓", "张伟铠", "夏志琴", "邓诗林", "张钰", "李欢", "邵进杰", "吴双烨", "李佳敏", "易业煜", "陈佳豪", "范慧珍", "丁佳宜", "吴浪宇", "赖广连", "朱凯涛", "朱光晖", "李泉", "刘一鸣", "李强", "朱哲", "黎子慧", "周伟", "彭宏宇", "金晓风", "张华文", "吴裕杨", "管睿松", "韩文秀", "胡志建"];
    // 定时器的全局变量
    let timerId = 0
    // 随机号要全局变量
    let random = 0
    // 业务1.开始按钮模块
    const qs = document.querySelector('.qs')
    // 1.1 获取开始按钮对象
    const start = document.querySelector('.start')
    // 1.2 添加点击事件
    start.addEventListener('click', function () {
      timerId = setInterval(function () {
        // 随机数
        random = parseInt(Math.random() * arr.length)
        // console.log(arr[random])
        qs.innerHTML = arr[random]
      }, 100)
    })
    let i = 10
    let cTimer = null;
    // 2. 关闭按钮模块
    const end = document.querySelector('.end')
    end.addEventListener('click', function () {
      clearInterval(timerId)
      start.innerHTML='不能点'
      cTimer = setInterval(function () {
        i--
        console.log(i);
        if (i === 0) {
          i = 10
          start.click()
          clearInterval(cTimer)
        }
      }, 500)

    })
  </script>
</body>

</html>